package org.demo2.springmvc_demo3.service;

import org.demo2.springmvc_demo3.dto.UserDTO;
import org.demo2.springmvc_demo3.entity.User;
import org.demo2.springmvc_demo3.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

//Service的实现类
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public void register(UserDTO userDTO) {
        // 验证用户名是否重复
        // 目前代码未实现验证逻辑，可后续添加

        // 把DTO转成实体类
        User user = new User();
        user.setUsername(userDTO.getUsername());
        user.setPassword(userDTO.getPassword());
        user.setEmail(userDTO.getEmail());
        user.setSex("");
        user.setRole("普通用户");
        // 把数据存入数据库
        userMapper.addUser(user);
    }

}
